package edu.hhu.wifispark.entry;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;


public class Record extends Model<Record>{

	private static final long serialVersionUID = 1L;
	public final static Record dao = new Record();
	
	public String peri;
	
	public List<Record> FindMac(){
		String sql = "SELECT mac, COUNT(1) AS counts, SUM(staytime) FROM record GROUP BY mac";
		return find(sql);
	}
	
	public List<Record> findCustomerInfo(long stime,long etime){
		String sql = "SELECT mac, COUNT(1) AS counts, SUM(staytime) as sums,'000' as peri FROM record  WHERE entertime > "
				+ stime
				+ " AND entertime < "
				+ etime+" GROUP BY mac";
		System.out.println(sql);
		return find(sql);
	}
	public List<Record> FindPeriod(long etime){
		String sql = "SELECT mac,SUBSTRING_INDEX(GROUP_CONCAT(entertime ORDER BY entertime DESC),',',2) as peri FROM record  WHERE entertime < "
				+ etime
				+ " GROUP BY mac ";
		System.out.println(sql);
		return find(sql);
	}
//	public List<Record> FindPeriod(String mac, long stime, long etime){
//		String sql = "SELECT * FROM record WHERE mac = '" + mac + "' AND entertime > " +stime+" AND entertime < "+etime+" ORDER BY entertime DESC LIMIT 2";
//		return find(sql);
//	}
}
